#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> 

#include "commprefs_gui.h"
#include "utils.h"

CommPrefs_Gui *cp_gui;

void build_commprefs_gui(void) {
    cp_gui = calloc(1, sizeof(CommPrefs_Gui));

    // Main window
    cp_gui->win = etk_window_new();
    etk_window_title_set(ETK_WINDOW(cp_gui->win), "E-Mail configuration");
    //etk_window_resize(ETK_WINDOW(cp_gui->win), 500, 400);	// Comment this line for autofit
    etk_container_border_width_set(ETK_CONTAINER(cp_gui->win), 5);

    cp_gui->mainvbox = etk_vbox_new(ETK_FALSE, 3);
    etk_container_add(ETK_CONTAINER(cp_gui->win), cp_gui->mainvbox);

    // Main notebook and pages
    cp_gui->maintabs = etk_notebook_new();

    cp_gui->rcv_p = calloc(1, sizeof(Prefs_Page_Receive));
    cp_gui->rcv_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Receive", ETK_WIDGET(cp_gui->tabpage)); 
    cp_gui->rcv_p->hbox = etk_hbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->maintabs), cp_gui->rcv_p->pageid, ETK_WIDGET(cp_gui->rcv_p->hbox));
    cp_gui->rcv_p->vbox1 = etk_vbox_new(ETK_FALSE, 0);
    etk_container_add(ETK_CONTAINER(cp_gui->rcv_p->hbox), ETK_WIDGET(cp_gui->rcv_p->vbox1));
    cp_gui->rcv_p->vbox2 = etk_vbox_new(ETK_FALSE, 0);
    etk_container_add(ETK_CONTAINER(cp_gui->rcv_p->hbox), ETK_WIDGET(cp_gui->rcv_p->vbox2));            
    cp_gui->rcv_p->autocheck_every = etk_check_button_new_with_label("Auto check new mail every");
    cp_gui->rcv_p->autocheck_mins = etk_spinner_new(1, 100, 10, 1, 5);
    cp_gui->rcv_p->check_startup = etk_check_button_new_with_label("Check new mail on startup");
    cp_gui->rcv_p->mail_command = etk_check_button_new_with_label("Execute command at new message");
    cp_gui->rcv_p->command = etk_entry_new();
	etk_box_append(ETK_BOX(cp_gui->rcv_p->vbox1), ETK_WIDGET(cp_gui->rcv_p->autocheck_every), ETK_BOX_START, ETK_BOX_NONE, 0);
	etk_box_append(ETK_BOX(cp_gui->rcv_p->vbox1), ETK_WIDGET(cp_gui->rcv_p->mail_command), ETK_BOX_START, ETK_BOX_NONE, 0);
	etk_box_append(ETK_BOX(cp_gui->rcv_p->vbox1), ETK_WIDGET(cp_gui->rcv_p->check_startup), ETK_BOX_START, ETK_BOX_NONE, 0);
	etk_box_append(ETK_BOX(cp_gui->rcv_p->vbox2), ETK_WIDGET(cp_gui->rcv_p->autocheck_mins), ETK_BOX_START, ETK_BOX_NONE, 0);		
	etk_box_append(ETK_BOX(cp_gui->rcv_p->vbox2), ETK_WIDGET(cp_gui->rcv_p->command), ETK_BOX_START, ETK_BOX_NONE, 0);
    
    cp_gui->snd_p = calloc(1, sizeof(Prefs_Page_Send));
    cp_gui->snd_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Send", ETK_WIDGET(cp_gui->tabpage));
    cp_gui->snd_p->vbox = etk_vbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->maintabs), cp_gui->snd_p->pageid, ETK_WIDGET(cp_gui->snd_p->vbox));
	cp_gui->snd_p->save_sent = etk_check_button_new_with_label("Save sent messages to outbox");
	cp_gui->snd_p->apply_filters = etk_check_button_new_with_label("Apply filter rules to sent messages");
    cp_gui->snd_p->label = etk_label_new("Transfer encoding");
    cp_gui->snd_p->trans_enc = etk_combobox_new_default();
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->trans_enc), "Automatic");
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->trans_enc), "Base64");
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->trans_enc), "Quoted-printable");
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->trans_enc), "8bit");    
    cp_gui->snd_p->hbox1 = etk_hbox_new(ETK_FALSE, 0);
    etk_box_append(ETK_BOX(cp_gui->snd_p->vbox), ETK_WIDGET(cp_gui->snd_p->save_sent), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->snd_p->vbox), ETK_WIDGET(cp_gui->snd_p->apply_filters), ETK_BOX_START, ETK_BOX_NONE, 0);    
    etk_container_add(ETK_CONTAINER(cp_gui->snd_p->vbox), ETK_WIDGET(cp_gui->snd_p->hbox1));
    etk_box_append(ETK_BOX(cp_gui->snd_p->hbox1), ETK_WIDGET(cp_gui->snd_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->snd_p->hbox1), ETK_WIDGET(cp_gui->snd_p->trans_enc), ETK_BOX_START, ETK_BOX_NONE, 3);
    cp_gui->snd_p->hbox2 = etk_hbox_new(ETK_FALSE, 0);
    etk_container_add(ETK_CONTAINER(cp_gui->snd_p->vbox), ETK_WIDGET(cp_gui->snd_p->hbox2));
    cp_gui->snd_p->label = etk_label_new("MIME filename encoding");
    cp_gui->snd_p->mime_enc = etk_combobox_new_default();
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->mime_enc), "MIME hedaer");
    etk_combobox_item_append(ETK_COMBOBOX(cp_gui->snd_p->mime_enc), "RFC 2231");
    etk_box_append(ETK_BOX(cp_gui->snd_p->hbox2), ETK_WIDGET(cp_gui->snd_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->snd_p->hbox2), ETK_WIDGET(cp_gui->snd_p->mime_enc), ETK_BOX_START, ETK_BOX_NONE, 3);
    
    cp_gui->cmp_p = calloc(1, sizeof(Prefs_Page_Compose));
    cp_gui->cmp_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Compose", ETK_WIDGET(cp_gui->tabpage));
    cp_gui->cmp_p->vbox = etk_vbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->maintabs), cp_gui->cmp_p->pageid, ETK_WIDGET(cp_gui->cmp_p->vbox));
    cp_gui->cmp_p->cmp_tabs = etk_notebook_new();
    //
    cp_gui->cmp_p->gen_p = calloc(1, sizeof(Prefs_Page_Compose_General_Page));
    cp_gui->cmp_p->gen_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), "General", ETK_WIDGET(cp_gui->cmp_p->tabpage));
    cp_gui->cmp_p->gen_p->vbox = etk_vbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), cp_gui->cmp_p->gen_p->pageid, ETK_WIDGET(cp_gui->cmp_p->gen_p->vbox));
    cp_gui->cmp_p->gen_p->sign_frm = etk_frame_new(" Signature ");
    cp_gui->cmp_p->gen_p->sign_hbox = etk_hbox_new(ETK_FALSE, 0);
    cp_gui->cmp_p->gen_p->label = etk_label_new("Signature separator");
    cp_gui->cmp_p->gen_p->sign_sep = etk_entry_new();
    cp_gui->cmp_p->gen_p->ins_auto = etk_check_button_new_with_label("Autoinsert"); 
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->sign_hbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->label), ETK_BOX_START, ETK_BOX_NONE, 3);    
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->sign_hbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->sign_sep), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->sign_hbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->ins_auto), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_bin_child_set(ETK_BIN(cp_gui->cmp_p->gen_p->sign_frm), ETK_WIDGET(cp_gui->cmp_p->gen_p->sign_hbox));
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->sign_frm), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->gen_p->reply_frm = etk_frame_new(" Reply ");
    cp_gui->cmp_p->gen_p->reply_vbox = etk_vbox_new(ETK_FALSE, 0);
    cp_gui->cmp_p->gen_p->auto_sel_acct = etk_check_button_new_with_label("Autoselect account for replies");
    cp_gui->cmp_p->gen_p->quote_msg = etk_check_button_new_with_label("Quote message when replying");
    cp_gui->cmp_p->gen_p->rply_ml_rply = etk_check_button_new_with_label("Reply button invokes mailing list reply");    
    cp_gui->cmp_p->gen_p->inherit_on_rply = etk_check_button_new_with_label("Inherit recipients on reply to self messages");
    etk_bin_child_set(ETK_BIN(cp_gui->cmp_p->gen_p->reply_frm), ETK_WIDGET(cp_gui->cmp_p->gen_p->reply_vbox));
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->auto_sel_acct), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->quote_msg), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->rply_ml_rply), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->inherit_on_rply), ETK_BOX_START, ETK_BOX_NONE, 3);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->gen_p->vbox), ETK_WIDGET(cp_gui->cmp_p->gen_p->reply_frm), ETK_BOX_END, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->vbox), ETK_WIDGET(cp_gui->cmp_p->cmp_tabs), ETK_BOX_START, ETK_BOX_NONE, 0);
    //
    cp_gui->cmp_p->edit_p = calloc(1, sizeof(Prefs_Page_Compose_Editor_Page));
    cp_gui->cmp_p->edit_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), "Editor", ETK_WIDGET(cp_gui->cmp_p->tabpage));
    cp_gui->cmp_p->edit_p->vbox = etk_vbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), cp_gui->cmp_p->edit_p->pageid, ETK_WIDGET(cp_gui->cmp_p->edit_p->vbox));
    cp_gui->cmp_p->edit_p->auto_ext_ed = etk_check_button_new_with_label("Autolaunch the external editor");
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->auto_ext_ed), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->hbox1 = etk_hbox_new(ETK_FALSE, 3);
    cp_gui->cmp_p->edit_p->label = etk_label_new("Undo level");
    cp_gui->cmp_p->edit_p->undo_spn = etk_spinner_new(0.0, 100.0, 50.0, 1.0, 5.0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox1), ETK_WIDGET(cp_gui->cmp_p->edit_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox1), ETK_WIDGET(cp_gui->cmp_p->edit_p->undo_spn), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->hbox2 = etk_hbox_new(ETK_FALSE, 3);
    cp_gui->cmp_p->edit_p->label = etk_label_new("Wrap messages at");
    cp_gui->cmp_p->edit_p->wrap_spn = etk_spinner_new(20.0, 1024.0, 72.0, 1.0, 5.0);    
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox2), ETK_WIDGET(cp_gui->cmp_p->edit_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox2), ETK_WIDGET(cp_gui->cmp_p->edit_p->wrap_spn), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->label = etk_label_new("characters.");    
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox2), ETK_WIDGET(cp_gui->cmp_p->edit_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->wrap_quot = etk_check_button_new_with_label("Wrap quotation");
    cp_gui->cmp_p->edit_p->wrap_on_in = etk_check_button_new_with_label("Wrap on input");
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->hbox1), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->hbox2), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->wrap_quot), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->wrap_on_in), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->hbox3 = etk_hbox_new(ETK_FALSE, 3);
    cp_gui->cmp_p->edit_p->autosave = etk_check_button_new_with_label("Auto-save to Draft");
    cp_gui->cmp_p->edit_p->label = etk_label_new("every");
    cp_gui->cmp_p->edit_p->autosave_spn = etk_spinner_new(1.0, 100.0, 5.0, 1.0, 5.0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox3), ETK_WIDGET(cp_gui->cmp_p->edit_p->autosave), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox3), ETK_WIDGET(cp_gui->cmp_p->edit_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox3), ETK_WIDGET(cp_gui->cmp_p->edit_p->autosave_spn), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->edit_p->label = etk_label_new("minute(s)");
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->hbox3), ETK_WIDGET(cp_gui->cmp_p->edit_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->edit_p->vbox), ETK_WIDGET(cp_gui->cmp_p->edit_p->hbox3), ETK_BOX_START, ETK_BOX_NONE, 0);    
    //
    cp_gui->cmp_p->fmt_p = calloc(1, sizeof(Prefs_Page_Compose_Format_Page));
    cp_gui->cmp_p->fmt_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), "Format", ETK_WIDGET(cp_gui->cmp_p->tabpage));
    cp_gui->cmp_p->fmt_p->vbox = etk_vbox_new(ETK_FALSE, 0);
    etk_notebook_page_child_set(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), cp_gui->cmp_p->fmt_p->pageid, ETK_WIDGET(cp_gui->cmp_p->fmt_p->vbox));
    cp_gui->cmp_p->fmt_p->reply_frm = etk_frame_new(" Reply format ");
    cp_gui->cmp_p->fmt_p->reply_vbox = etk_vbox_new(ETK_FALSE, 0);
    cp_gui->cmp_p->fmt_p->hbox1 = etk_hbox_new(ETK_FALSE, 3);
    cp_gui->cmp_p->fmt_p->label = etk_label_new("Quotation mark");
    cp_gui->cmp_p->fmt_p->reply_qmark = etk_entry_new();
    cp_gui->cmp_p->fmt_p->reply_format = etk_text_view_new();
    cp_gui->cmp_p->fmt_p->reply_iter = etk_textblock_iter_new(ETK_TEXT_VIEW(cp_gui->cmp_p->fmt_p->reply_format)->textblock);
    cp_gui->cmp_p->fmt_p->reply_iter = etk_text_view_cursor_get(ETK_TEXT_VIEW(cp_gui->cmp_p->fmt_p->reply_format));
    etk_textblock_insert(ETK_TEXT_VIEW(cp_gui->cmp_p->fmt_p->reply_format)->textblock, cp_gui->cmp_p->fmt_p->reply_iter, "On %d", strlen("On %d"));
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->hbox1), ETK_WIDGET(cp_gui->cmp_p->fmt_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->hbox1), ETK_WIDGET(cp_gui->cmp_p->fmt_p->reply_qmark), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->reply_frm), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->hbox1), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->reply_vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->reply_format), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_bin_child_set(ETK_BIN(cp_gui->cmp_p->fmt_p->reply_frm), ETK_WIDGET(cp_gui->cmp_p->fmt_p->reply_vbox));
    cp_gui->cmp_p->fmt_p->fwd_frm = etk_frame_new(" Forward format ");
    cp_gui->cmp_p->fmt_p->fwd_vbox = etk_vbox_new(ETK_FALSE, 0);
    cp_gui->cmp_p->fmt_p->hbox2 = etk_hbox_new(ETK_FALSE, 3);
    cp_gui->cmp_p->fmt_p->label = etk_label_new("Quotation mark");
    cp_gui->cmp_p->fmt_p->fwd_qmark = etk_entry_new();
    cp_gui->cmp_p->fmt_p->fwd_format = etk_text_view_new();
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->hbox2), ETK_WIDGET(cp_gui->cmp_p->fmt_p->label), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->hbox2), ETK_WIDGET(cp_gui->cmp_p->fmt_p->fwd_qmark), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_bin_child_set(ETK_BIN(cp_gui->cmp_p->fmt_p->fwd_frm), ETK_WIDGET(cp_gui->cmp_p->fmt_p->fwd_vbox));
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->fwd_frm), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->fwd_vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->hbox2), ETK_BOX_START, ETK_BOX_NONE, 0);
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->fwd_vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->fwd_format), ETK_BOX_START, ETK_BOX_NONE, 0);
    cp_gui->cmp_p->fmt_p->hlp_btn = etk_button_new_with_label("Description of symbols");
    etk_box_append(ETK_BOX(cp_gui->cmp_p->fmt_p->vbox), ETK_WIDGET(cp_gui->cmp_p->fmt_p->hlp_btn), ETK_BOX_START, ETK_BOX_SHRINK_OPPOSITE, 0);
    //
    cp_gui->cmp_p->spell_p = calloc(1, sizeof(Prefs_Page_Compose_Spell_Page));
    cp_gui->cmp_p->spell_p->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->cmp_p->cmp_tabs), "Spell checking", ETK_WIDGET(cp_gui->cmp_p->tabpage));
       
    cp_gui->display_page = calloc(1, sizeof(Prefs_Page));
    cp_gui->display_page->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Display", ETK_WIDGET(cp_gui->tabpage));
    cp_gui->junk_page = calloc(1, sizeof(Prefs_Page));	
    cp_gui->junk_page->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Junk mail",  ETK_WIDGET(cp_gui->tabpage));
    cp_gui->privacy_page = calloc(1, sizeof(Prefs_Page));
    cp_gui->privacy_page->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Privacy", ETK_WIDGET(cp_gui->tabpage));
    cp_gui->details_page = calloc(1, sizeof(Prefs_Page));
    cp_gui->details_page->pageid = etk_notebook_page_append(ETK_NOTEBOOK(cp_gui->maintabs), "Details", ETK_WIDGET(cp_gui->tabpage));
    etk_box_append(ETK_BOX(cp_gui->mainvbox), ETK_WIDGET(cp_gui->maintabs), ETK_BOX_START, ETK_BOX_EXPAND_FILL, 3);
    // Main notebook and pages END

    // Hbox buttons
    cp_gui->buttonshbox = etk_hbox_new(ETK_TRUE, 0);
    etk_box_append(ETK_BOX(cp_gui->mainvbox), ETK_WIDGET(cp_gui->buttonshbox), ETK_BOX_END, ETK_BOX_NONE, 3);
    cp_gui->buttons = etk_button_new_from_stock(ETK_STOCK_DIALOG_APPLY);
    etk_box_append(ETK_BOX(cp_gui->buttonshbox), ETK_WIDGET(cp_gui->buttons), ETK_BOX_END, ETK_BOX_NONE, 3);	
    cp_gui->buttons = etk_button_new_from_stock(ETK_STOCK_DIALOG_CANCEL);
    etk_box_append(ETK_BOX(cp_gui->buttonshbox), ETK_WIDGET(cp_gui->buttons), ETK_BOX_END, ETK_BOX_NONE, 3);
    cp_gui->buttons = etk_button_new_from_stock(ETK_STOCK_DIALOG_OK);
    etk_box_append(ETK_BOX(cp_gui->buttonshbox), ETK_WIDGET(cp_gui->buttons), ETK_BOX_END, ETK_BOX_NONE, 3);
    // Hbox buttons END

    etk_widget_show_all(cp_gui->win);
}

void _commprefs_quit_cb(void *data) {
    //etk_main_quit();
    //etk_widget_hide(ETK_WIDGET(cp_gui->win));
}
